import javax.swing.text.html.parser.Entity;
import java.util.*;
import java.util.function.BiConsumer;;

public class Exam01 {
    //创建⼀个HashMap集合，使⽤三种遍历⽅式输出集合中的元素。
    public static void main(String[] args) {
        HashMap<Integer,String> hashMap = new HashMap<>();
        hashMap.put(1, "安琪拉");
        hashMap.put(2, "妲己");
        hashMap.put(3, "貂蝉");
        hashMap.put(4, "大乔");

        //forEach
        hashMap.forEach((key,value) -> System.out.println(key + value));

       hashMap.forEach(new BiConsumer<Integer, String>() {
           @Override
           public void accept(Integer integer, String s) {
               System.out.println(integer + "->"+ s);
           }
       });
        //迭代器
        Set<Integer> set = hashMap.keySet();
        Iterator<Integer> iterator = set.iterator();
        while (iterator.hasNext()) {
            Integer key = iterator.next();
            String value = hashMap.get(key);
            System.out.println(key + "-->" + value);
        }
        // 获取所有键值对的Set集合
        Set<Map.Entry<Integer, String>> entrySet = hashMap.entrySet();
        entrySet.forEach(entry -> { // entry 一个键值对组合
            System.out.println(entry.getKey() + "====" + entry.getValue());
        });
        System.out.println(hashMap);

    }
}
